import requests
from lxml import etree

base_url = "https://www.inventchina.cn/"


def search_product(procode: str) -> etree._Element:
    """
    获取搜索结果
    
    Args:
        procode (str)

    Returns:
        etree._Element: _description_
    """
    headers = {
        "content-type":
        "application/x-www-form-urlencoded",
        "origin":
        "https://www.inventchina.cn",
        "referer":
        "https://www.inventchina.cn/product_m.asp",
        "user-agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
    }

    url = "https://www.inventchina.cn/product_m.asp"
    data = {"ProName": procode, "login": " "}
    response = requests.post(url, headers=headers, data=data)
    page = etree.HTML(response.text)
    return page


def get_prourl(page) -> str:
    url = page.xpath('//div[@class="prodiv wow fadeInLeft"][1]/a/@href')[0]
    return base_url + url


def get_predes(page) ->str:
    url = page.xpath()